package com.example.imtoken.modules.main.my

import android.content.Intent
import android.view.View
import androidx.navigation.fragment.findNavController
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ClickUtils
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseFragment
import com.example.imtoken.core.utils.NavOptionsUtils.navOptions
import com.example.imtoken.databinding.MyFragmentBinding
import com.example.imtoken.modules.help_h5.HelpH5Activity
import com.example.imtoken.modules.main.my.address.AddressActivity
import com.example.imtoken.modules.main.wallet.manage.wallet.ManageWalletActivity

/**
 * 我
 */
class MyFragment : BaseFragment<MyViewModel, MyFragmentBinding>(MyViewModel::class.java) {

    private val help1 = "http://116.211.17.118:9998/#/walletUi/HelpAndFeedback"
    private val help2 = "http://116.211.17.118:9998/#/walletUi/Guide"
    private val help3 = "http://116.211.17.118:9998/#/walletUi/Protocol"

    override fun initLayoutId(): Int {
        return R.layout.my_fragment
    }

    override fun init() {
        dataBinding.fragment = this
        dataBinding.include2.tvHeadTitles.text = getString(R.string.my)
        initView()

        initClick()
    }

    private fun initClick() {
        ClickUtils.applyGlobalDebouncing(dataBinding.llHelp1) {
            val intent = Intent(activity, HelpH5Activity::class.java)
            intent.putExtra("title", getString(R.string.helpAndFeedback))
            intent.putExtra("url", help1)
            ActivityUtils.startActivity(intent)
        }
        ClickUtils.applyGlobalDebouncing(dataBinding.llHelp2) {
            val intent = Intent(activity, HelpH5Activity::class.java)
            intent.putExtra("title", getString(R.string.walletGuide))
            intent.putExtra("url", help2)
            ActivityUtils.startActivity(intent)
        }
        ClickUtils.applyGlobalDebouncing(dataBinding.llHelp3) {
            val intent = Intent(activity, HelpH5Activity::class.java)
            intent.putExtra("title", getString(R.string.userAgreement))
            intent.putExtra("url", help3)
            ActivityUtils.startActivity(intent)
        }
        ClickUtils.applyGlobalDebouncing(dataBinding.llManageWallet) {
            //管理钱包
            ActivityUtils.startActivity(ManageWalletActivity::class.java)
        }
        ClickUtils.applyGlobalDebouncing(dataBinding.llAddressBook) {
            //地址本
            ActivityUtils.startActivity(AddressActivity::class.java)
        }
    }

    private fun initView() {
        dataBinding.include2.ivHeadBack.visibility = View.GONE
    }

    fun gotoSettingFragment() {
        findNavController().navigate(
            R.id.action_mainFragment_to_settingFragment,
            null,
            navOptions()
        )
    }

}